<template>
  <el-rate v-model="keyword" @change="changeBtn" v-bind="{
    'show-text': !!$attrs.texts,//是否显示辅助文本
    'show-score': !!$attrs['score-template'],//是否显示辅助文本
    'allow-half': true,//允许半选
    ...$attrs,
    disabled: typeof $attrs.disabled === 'function' ? $attrs.disabled(data) : $attrs.disabled
  }" />
</template>
<script setup lang="ts">
//获取父级数据
const props = withDefaults(
  defineProps<{
    data: any;
    dataName?: any;
  }>(),
  {

  },
);
const emit = defineEmits<{
  //fn为父组件引入子组件是定义的子组件事件属性，可随意定义
  (event: 'changeBtn', val: any, row: any): void;
}>();
const keyword = computed({
  get() {
    if (props.dataName) {
      return props.data[props.dataName];
    } else {
      return props.data;
    }
  },
  set(val) {
    if (props.dataName) {
      props.data[props.dataName] = val;
    } else {
      props.data = val;
    }
  },
});
const changeBtn = (val: any) => {
  emit('changeBtn', val, props.data);
};
onMounted(() => { });
</script>
<style scoped></style>
